/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassandrawindow;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.Statement;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author MT844
 */
public class MysqlGoogleAdword {
    
    private Connection conn = null;     
    public static final String ban_data_adwords = "ad_ban_date";
    public static final int priceAdwords = 2200;
    
    
    public MysqlGoogleAdword() {
        try
        {
           Class.forName("com.mysql.jdbc.Driver").newInstance();            
           conn = (Connection) DriverManager.getConnection(ACCOUNT.URL_MYSQL_MAIN_ADWORDS , ACCOUNT.username_mysql_main_adwords, ACCOUNT.pass_mysql_main_adwords);//abc!@#           
           Debug.println("Connected to MySQL Server database 7.136");
        }
       catch (Exception ex)
       {
           Debug.println("Couldn't connect to the MySQL database 7.136  Make sure the MySQL connector jar is in the lib directory.  See the installation documentation for more information. ");
           Debug.println(ex.getMessage());
       }
    }
    
    public void shutdownConnection()
    {
        try {
            conn.close();
            conn = null;            
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }
    
    public Map getDataAdwordsByDate (String date){
        
        Map<String,String> mapReturn    =   new HashMap<>();
        try
        {
            Statement st= (Statement)conn.createStatement();            
            String sql = "SELECT adm_camp_id,adm_ban_id,totalclick,totalview FROM "+ ban_data_adwords +" WHERE dt ='"+date+"'";
            Debug.println(sql);
            ResultSet rs = st.executeQuery(sql);            
           
            while (rs.next())
            {
                mapReturn.put(rs.getString("adm_camp_id")+"-"+rs.getString("adm_ban_id"), rs.getString("totalclick")+"-"+rs.getString("totalview"));
            }
            rs.close();
            st.close();
        }
        catch (Exception ex)
        {
            Debug.println(ex.getMessage());
            Debug.println("Couldn't connect to the MySQL database 7.136");
        }

        return mapReturn;
    }
    
    
    
    
    
    
}
